home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / server / scripts / car.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  6.0 KB  |  188 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7.  
  8. // Information extacted from the shape.
  9. //
  10. // Wheel Sequences
  11. //    spring#        Wheel spring motion: time 0 = wheel fully extended,
  12. //                   the hub must be displaced, but not directly animated
  13. //                   as it will be rotated in code.
  14. // Other Sequences
  15. //    steering       Wheel steering: time 0 = full right, 0.5 = center
  16. //    breakLight     Break light, time 0 = off, 1 = breaking
  17. //
  18. // Wheel Nodes
  19. //    hub#           Wheel hub, the hub must be in it's upper position
  20. //                   from which the springs are mounted.
  21. //
  22. // The steering and animation sequences are optional.
  23. // The center of the shape acts as the center of mass for the car.
  24.  
  25. //-----------------------------------------------------------------------------
  26. datablock AudioProfile(buggyEngineSound)
  27. {
  28.    filename    = "~/data/sound/vehicles/buggy/engine_idle.wav";
  29.    description = AudioClosestLooping3d;
  30.    preload = true;
  31. };
  32.  
  33. datablock ParticleData(TireParticle)
  34. {
  35.    textureName          = "~/data/shapes/buggy/dustParticle";
  36.    dragCoefficient      = 2.0;
  37.    gravityCoefficient   = -0.1;
  38.    inheritedVelFactor   = 0.1;
  39.    constantAcceleration = 0.0;
  40.    lifetimeMS           = 1000;
  41.    lifetimeVarianceMS   = 0;
  42.    colors[0]     = "0.46 0.36 0.26 1.0";
  43.    colors[1]     = "0.46 0.46 0.36 0.0";
  44.    sizes[0]      = 0.50;
  45.    sizes[1]      = 1.0;
  46. };
  47.  
  48. datablock ParticleEmitterData(TireEmitter)
  49. {
  50.    ejectionPeriodMS = 10;
  51.    periodVarianceMS = 0;
  52.    ejectionVelocity = 1;
  53.    velocityVariance = 1.0;
  54.    ejectionOffset   = 0.0;
  55.    thetaMin         = 5;
  56.    thetaMax         = 20;
  57.    phiReferenceVel  = 0;
  58.    phiVariance      = 360;
  59.    overrideAdvance = false;
  60.    particles = "TireParticle";
  61. };
  62.  
  63.  
  64. //----------------------------------------------------------------------------
  65.  
  66. datablock WheeledVehicleTire(DefaultCarTire)
  67. {
  68.    // Tires act as springs and generate lateral and longitudinal
  69.    // forces to move the vehicle. These distortion/spring forces
  70.    // are what convert wheel angular velocity into forces that
  71.    // act on the rigid body.
  72.    shapeFile = "~/data/shapes/buggy/wheel.dts";
  73.    staticFriction = 4;
  74.    kineticFriction = 1.25;
  75.  
  76.    // Spring that generates lateral tire forces
  77.    lateralForce = 18000;
  78.    lateralDamping = 4000;
  79.    lateralRelaxation = 1;
  80.  
  81.    // Spring that generates longitudinal tire forces
  82.    longitudinalForce = 18000;
  83.    longitudinalDamping = 4000;
  84.    longitudinalRelaxation = 1;
  85. };
  86.  
  87. datablock WheeledVehicleSpring(DefaultCarSpring)
  88. {
  89.    // Wheel suspension properties
  90.    length = 0.85;             // Suspension travel
  91.    force = 3000;              // Spring force
  92.    damping = 600;             // Spring damping
  93.    antiSwayForce = 3;         // Lateral anti-sway force
  94. };
  95.  
  96. datablock WheeledVehicleData(DefaultCar)
  97. {
  98.    category = "Vehicles";
  99.    shapeFile = "~/data/shapes/buggy/buggy.dts";
  100.    emap = true;
  101.  
  102.    maxDamage = 1.0;
  103.    destroyedLevel = 0.5;
  104.  
  105.    maxSteeringAngle = 0.785;  // Maximum steering angle, should match animation
  106.    tireEmitter = TireEmitter; // All the tires use the same dust emitter
  107.  
  108.    // 3rd person camera settings
  109.    cameraRoll = true;         // Roll the camera with the vehicle
  110.    cameraMaxDist = 6;         // Far distance from vehicle
  111.    cameraOffset = 1.5;        // Vertical offset from camera mount point
  112.    cameraLag = 0.1;           // Velocity lag of camera
  113.    cameraDecay = 0.75;        // Decay per sec. rate of velocity lag
  114.  
  115.    // Rigid Body
  116.    mass = 200;
  117.    massCenter = "0 -0.5 0";    // Center of mass for rigid body
  118.    massBox = "0 0 0";         // Size of box used for moment of inertia,
  119.                               // if zero it defaults to object bounding box
  120.    drag = 0.6;                // Drag coefficient
  121.    bodyFriction = 0.6;
  122.    bodyRestitution = 0.4;
  123.    minImpactSpeed = 5;        // Impacts over this invoke the script callback
  124.    softImpactSpeed = 5;       // Play SoftImpact Sound
  125.    hardImpactSpeed = 15;      // Play HardImpact Sound
  126.    integration = 4;           // Physics integration: TickSec/Rate
  127.    collisionTol = 0.1;        // Collision distance tolerance
  128.    contactTol = 0.1;          // Contact velocity tolerance
  129.  
  130.    // Engine
  131.    engineTorque = 4000;       // Engine power
  132.    engineBrake = 600;         // Braking when throttle is 0
  133.    brakeTorque = 8000;        // When brakes are applied
  134.    maxWheelSpeed = 30;        // Engine scale by current speed / max speed
  135.  
  136.    // Energy
  137.    maxEnergy = 100;
  138.    jetForce = 3000;
  139.    minJetEnergy = 30;
  140.    jetEnergyDrain = 2;
  141.  
  142.    // Sounds
  143. //   jetSound = ScoutThrustSound;
  144. //   engineSound = BuggyEngineSound;
  145. //   squealSound = ScoutSquealSound;
  146. //   softImpactSound = SoftImpactSound;
  147. //   hardImpactSound = HardImpactSound;
  148. //   wheelImpactSound = WheelImpactSound;
  149.  
  150. //   explosion = VehicleExplosion;
  151. };
  152.  
  153.  
  154. //-----------------------------------------------------------------------------
  155.  
  156. function WheeledVehicleData::create(%block)
  157. {
  158.    %obj = new WheeledVehicle() {
  159.       dataBlock = %block;
  160.    };
  161.    return(%obj);
  162. }
  163.  
  164. //-----------------------------------------------------------------------------
  165.  
  166. function WheeledVehicleData::onAdd(%this,%obj)
  167. {
  168.    // Setup the car with some defaults tires & springs
  169.    for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--) {
  170.       %obj.setWheelTire(%i,DefaultCarTire);
  171.       %obj.setWheelSpring(%i,DefaultCarSpring);
  172.       %obj.setWheelPowered(%i,false);
  173.    }
  174.    
  175.    // Steer front tires
  176.    %obj.setWheelSteering(0,1);
  177.    %obj.setWheelSteering(1,1);
  178.  
  179.    // Only power the two rear wheels...
  180.    %obj.setWheelPowered(2,true);
  181.    %obj.setWheelPowered(3,true);
  182. }
  183.  
  184. function WheeledVehicleData::onCollision(%this,%obj,%col,%vec,%speed)
  185. {
  186.    // Collision with other objects, including items
  187. }   
  188.